#ifndef SORTPROXYMODEL_H
#define SORTPROXYMODEL_H

#include <QSortFilterProxyModel>
#include <QStandardItemModel>
#include <QStandardItem>
#include <QDate>

class SortFilterProxyModel : public QSortFilterProxyModel
{
public:
    explicit SortFilterProxyModel(QObject *parent = nullptr): QSortFilterProxyModel(parent){

    }

    virtual bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override{
        auto model=dynamic_cast<QStandardItemModel*>(sourceModel());
        auto litem=model->itemFromIndex(source_left);
        auto ldat=litem->data();
        auto ritem=model->itemFromIndex(source_right);
        switch (ldat.toInt())
        {
        case 1 :
            return litem->text().toInt() < ritem->text().toInt();
        case 2:
            return litem->text().toDouble() < ritem->text().toDouble();
        case 3:{
            auto ld=QDate::fromString(litem->text(),"yyyy-MM-dd");
            auto rd=QDate::fromString(ritem->text(),"yyyy-MM-dd");
            return ld<rd;
        }
        default :
            return litem->text() < ritem->text();
        }

        return true;
    }

};

#endif // SORTPROXYMODEL_H
